home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-10 | 22.1 KB | 812 lines | [TEXT/MPS ] |
- /*---------------------------------------------------------------------------
- FILENAME
- DialogRoutines.c
-
- DESCRIPTION
- This file contains the routines which are used to process the LQ driver's
- sheetfeeder dialog.
-
- COPYRIGHT
- Copyright Apple Computer, Inc. 1992-1994
- All rights reserved.
-
- INTERFACE ROUTINES:
- DoSheetfeederDialog
-
- 12/20/93 dmh Sync'd with the shipping 1.0b3 GX driver.
- 8/28/94 dmh Sync'd with the shipping 1.0.1 GX driver.
-
- -------------------------------------------------------------------------------- */
-
- // Include the standard Mac header files
- #include "MacIncludes.h"
-
- // Include the new QuickDraw GX graphics header files
- #include <graphics routines.h>
- #include <graphics libraries.h>
- #include <math routines.h>
- #include <qd library.h>
-
- // Include the required Printing Manager header files
- #include <PrintingManager.h>
- #include <PrintingMessages.h>
- #include <PrintingDrivers.h>
- #include <Collections.h>
- #include <Messages.h>
- #include <PrintingResTypes.h>
- #include <PrintingErrors.h>
-
- #include <GXExceptions.h>
-
- // Include the internal driver constants and types used by this module
- #include "Resources.h"
- #include "UniversalMessageIntf.h"
- #include "DialogRoutines.h"
-
-
- /***************************************************************************************
- * CONSTANTS *
- ***************************************************************************************/
-
- // Constants for accessing items in the Sheetfeeder dialog
-
- #define kTray1Item 4 // Tray #1 pop-up menu
- #define kTray2Item 5 // Tray #2 pop-up menu
- #define kTray3Item 6 // Tray #3 pop-up menu
- #define kPrinterPICTItem 7 // Picture of the printer with a sheetfeeder
-
- // Constants useful for filtering events
-
- #define kENTER 0x03 // ENTER character
- #define kCR 0x0D // Carriage return character
-
- // Constants defining the maximum paper size supported by the LQ printer
-
- #define kMaxPaperWidth ff(15) // 15 inches is maximum width
- #define kMaxPaperHeight ff(69) // 69 inches is maximum height
-
-
- /*********************************************************************************
- * TYPES *
- *********************************************************************************/
-
- // PopupMenuInfo - Structure used to initialize the tray pop-up menus
-
- typedef struct
- {
- short numTrays; // Number of trays configured on the printer
- MenuHandle tray1Menu; // handle to the tray #1 pop-up menu
- MenuHandle tray2Menu; // handle to the tray #2 pop-up menu
- MenuHandle tray3Menu; // handle to the tray #3 pop-up menu
- } PopupMenuInfo,
- *PopupMenuInfoPtr;
-
-
- // PaperSearchRec - Structure used to search for a paper type chosen from a pop-up menu
-
- typedef struct
- {
- gxPaperType paper; // temp. paper type reference in which to return found paper type
- Str31 paperName; // name of the paper to locate
- } PaperSearchRec,
- *PaperSearchRecPtr;
-
-
- /***************************************************************************************
- * INLINE ROUTINES *
- ***************************************************************************************/
-
- pascal void QDDrawPicture(PicHandle myPicture,const Rect *dstRect) = 0xA8F6;
-
-
- /***************************************************************************************
- * INTERNAL ROUTINES *
- ***************************************************************************************/
-
-
- /****************************************************************************************
-
- FindChosenPaperType
-
- function:
- This routine is called by ForEachPaperTypeDo, and it searches for a specific
- paper type (by name). It terminates searching when the paper type is
- found. Only the names of paper that will fit into the printer will be considered.
-
-
- parameters:
- paper target paper type
- paperToFind structure that identifies the paper type to find
-
- returns:
- LoopStatus keepLooping => keep examining paper types
- stopLooping => no longer loop - we found the one we wanted
-
- ****************************************************************************************/
- pascal gxLoopStatus FindChosenPaperType(gxPaperType paper, PaperSearchRecPtr paperToFind)
- {
- Str31 paperName;
- gxLoopStatus status = gxKeepLooping;
- gxRectangle paperSize;
-
- // Get the dimensions of the paper
- GXGetPaperTypeDimensions(paper, nil, &paperSize);
-
- // Will the paper fit into the printer?
- if ( ( (paperSize.right - paperSize.left) <= FixMul(ff(72), kMaxPaperWidth) ) &&
- ( (paperSize.bottom - paperSize.top) <= FixMul(ff(72), kMaxPaperHeight) )
- )
- {
- // Retrieve the name of the paper type
- GXGetPaperTypeName(paper, paperName);
-
- if ( IUCompString(paperName, paperToFind->paperName) == 0 ) // T => Found the paper type
- {
- // Make a copy of this paper type and quit searching
- GXCopyPaperType (paper, paperToFind->paper);
- status = gxStopLooping;
- }
- }
-
- return(status);
- }
- /* FindChosenPaperType */
-
-
- /****************************************************************************************
-
- SaveSheetfeederSettings
-
- function:
- This routine is called if the user confirms the changes in the dialog. It
- stores updates the tray information configuration file with the user's latest
- settings.
-
- parameters:
- theDlog pointer to the target dialog
- menuStuff info. about the pop-up menus
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- OSErr SaveSheetfeederSettings(DialogPtr theDlog, PopupMenuInfoPtr menuStuff)
- {
- OSErr anErr;
- gxPaperType paper;
- gxJob theJob = GXGetJob();
- MenuHandle *nextMenu;
- short i;
-
- // Create a temporary paper type
-
- paper = GXNewPaperType(theJob, NULL, NULL, NULL);
- anErr = GXGetJobError(theJob);
- require(anErr == noErr, NewPaperType);
-
- // For each visible pop-up menu, update its associated tray information
-
- for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
- {
- short whichTray = i - kTray1Item + 1;
-
- if ( whichTray <= menuStuff->numTrays ) // T => This menu is visible
- {
- Str31 paperName;
- short itemType;
- ControlHandle item;
- Rect itemRect;
- PaperSearchRec paperToFind;
-
- // Get the name of the chosen paper type from the menu
-
- GetDItem(theDlog, i, &itemType, (Handle *) &item, &itemRect);
- GetItem(*nextMenu, GetCtlValue(item), paperName);
-
- // Get the tray information for this tray
-
- anErr = GXGetTrayPaperType(whichTray, paper);
- if (anErr == resNotFound)
- anErr = noErr;
- require(anErr == noErr, GetTrayPaperType);
-
- // Get the referenced paper type
-
- paperToFind.paper = paper;
- BlockMove((Ptr) paperName, (Ptr) paperToFind.paperName, sizeof(Str31));
-
- GXForEachJobPaperTypeDo(theJob, FindChosenPaperType, &paperToFind, false); // Don't consider the format device in this search
- anErr = GXGetJobError(theJob);
- require(anErr == noErr, ForEachPaperTypeDo);
-
- // Update the paper type for this tray
-
- anErr = GXSetTrayPaperType(whichTray, paper);
- require(anErr == noErr, SetTrayPaperType);
-
- }
- else // T => No more visible pop-up menus
- break;
- }
-
-
- /******* Clean-up *******/
-
- SetTrayPaperType:
- GetTrayPaperType:
- ForEachPaperTypeDo:
- GXDisposePaperType(paper);
-
- NewPaperType:
- return(anErr);
- }
- /* SaveSheetfeederSettings */
-
-
- /****************************************************************************************
-
- SheetfeederDialogFilter
-
- function:
- This routine is the filter proc. that is passed to ModalDialog when the
- sheetfeeder dialog is displayed. It filters for the <cr> and <enter> keys
- and for command-".".
-
- parameters:
- theDlog pointer to the target dialog
- theEvent the event to be filtered
- itemHit the item which was selected; may be mapped to ok or cancel
-
- returns:
- Boolean true if we've filtered the event; false if ModalDialog should process it
-
- ****************************************************************************************/
- pascal Boolean SheetfeederDialogFilter(DialogPtr theDlog, EventRecord *theEvent, short *itemHit)
- {
- Boolean eventFiltered = false;
- short itemType;
- Rect itemRect;
- Handle item;
-
- if ( (theEvent->what == keyDown) || (theEvent->what == autoKey) )
- {
- char c;
-
- c = (char) (theEvent->message & charCodeMask);
-
- if ( (c == kCR) || (c == kENTER) ) // T => User typed carriage return or enter key; filter event
- {
- *itemHit = ok;
- eventFiltered = true;
- }
- else
- if ( (c == '.') && ((theEvent->modifiers & cmdKey) != 0) ) // T => User typed <cmnd>-"."
- {
- *itemHit = cancel;
- eventFiltered = true;
- }
-
- if (eventFiltered) // T => Highlight the buttons appropriately
- {
- ControlHandle theCtrl;
- long ignore;
-
- // Highlight the OK button momentarily
-
- GetDItem(theDlog, *itemHit, &itemType, (Handle *) &theCtrl, &itemRect);
- HiliteControl(theCtrl, inButton);
- Delay(10, &ignore);
- HiliteControl(theCtrl, 0);
- }
- }
- else
- if (theEvent->what == updateEvt) // T => Outline the OK button
- {
- GrafPtr oldPort;
-
- GetPort(&oldPort);
- SetPort(theDlog);
-
- GetDItem(theDlog, ok, &itemType, &item, &itemRect);
- PenSize(3, 3);
- InsetRect(&itemRect, -4, -4);
- FrameRoundRect(&itemRect, 16, 16);
- PenNormal();
-
- SetPort(oldPort);
- }
-
- return(eventFiltered);
- }
- /* SheetfeederDialogFilter */
-
-
- /****************************************************************************************
-
- UniquePaperName
-
- function:
- This routine searches for a specified paper type name in a specific pop-up
- menu. If it finds the name, the routine returns false; otherwise it
- returns true.
-
- parameters:
- hMenu handle to the menu to examine
- paperName name of the paper type to insert to check for
-
- returns:
- Boolean true if paper type name is unique; false otherwise
-
- ****************************************************************************************/
- Boolean UniquePaperName(MenuHandle hMenu, Str31 paperName)
- {
- Boolean isUnique = true;
- short i;
- Str255 menuString;
-
- for (i = CountMItems(hMenu); i > 0; --i)
- {
- GetItem(hMenu, i, menuString);
-
- if ( IUCompString(paperName, menuString) == 0 ) // T => Found the string
- {
- isUnique = false;
- break;
- }
- }
-
- return(isUnique);
- }
- /* UniquePaperName */
-
-
- /****************************************************************************************
-
- AddPaperName
-
- function:
- This routine is called by ForEachPaperTypeDo, and it adds a paper name to
- each visible pop-up menu if the name does not already appear in the menu.
- Only the names of paper that will fit into the printer will be listed
- in the pop-up menu.
-
- parameters:
- paper target paper type
- menuStuff pointer to info about the dialog's pop-up menus
-
- returns:
- LoopStatus keepLooping => examine all target paper types
-
- ****************************************************************************************/
- pascal gxLoopStatus AddPaperName(gxPaperType paper, PopupMenuInfoPtr menuStuff)
- {
- Str31 paperName;
- gxRectangle paperSize;
-
- // Get the dimensions of the paper
- GXGetPaperTypeDimensions(paper, nil, &paperSize);
-
- // Will the paper fit into the printer?
- if ( ( (paperSize.right - paperSize.left) <= FixMul(ff(72), kMaxPaperWidth) ) &&
- ( (paperSize.bottom - paperSize.top) <= FixMul(ff(72), kMaxPaperHeight) )
- )
- {
- // Retrieve the name of the paper type
- GXGetPaperTypeName(paper, paperName);
-
- if ( UniquePaperName(menuStuff->tray1Menu, paperName) ) // T => If the paper name is unique, add it
- {
- MenuHandle *nextMenu;
- Str255 theName;
- short i;
-
- // For each visible menu, add the name to the pop-up
-
- for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
- {
- if ( (i - kTray1Item + 1) <= menuStuff->numTrays ) // T => This menu is visible
- {
- AppendMenu(*nextMenu, "\p ");
- BlockMove(paperName, theName, sizeof(Str31));
- SetItem(*nextMenu, CountMItems(*nextMenu), theName);
- }
- else // T => No more visible pop-up menus
- break;
- }
- }
- }
-
- return (gxKeepLooping);
- }
- /* AddPaperName */
-
-
- /****************************************************************************************
-
- LoadPaperNames
-
- function:
- This routine loads the names of each uniquely named paper type into each of the
- tray pop-up menus that are still visible.
-
- parameters:
- pDlg Pointer to the target dialog
- whichItem Index in the DITL of the item to draw
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- OSErr LoadPaperNames(DialogPtr theDlog, PopupMenuInfoPtr menuStuff)
- {
- short itemType;
- Rect itemRect;
- ControlHandle item;
- short i;
- gxJob theJob = GXGetJob();
- OSErr anErr;
-
- GXForEachJobPaperTypeDo(theJob, AddPaperName, menuStuff, false); // Don't consider the format device in this search
- anErr = GXGetJobError(theJob);
-
- if (anErr == noErr)
- {
- MenuHandle *nextMenu;
-
- // For each visible menu, initialize the pop-up control
-
- for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
- {
- if ( (i - kTray1Item + 1) <= menuStuff->numTrays ) // T => This menu is visible
- {
- GetDItem(theDlog, i, &itemType, (Handle *) &item, &itemRect);
-
- SetCtlMin(item, 1);
- SetCtlMax(item, CountMItems(*nextMenu));
- SetCtlValue(item, 1);
- }
- else // T => No more visible pop-up menus
- break;
- }
- }
-
- return(anErr);
- }
- /* LoadPaperNames */
-
-
- /****************************************************************************************
-
- SheetfeederDrawProc
-
- function:
- This routine is used to draw the picture of the sheetfeeder in the configuration
- dialog.
-
- parameters:
- pDlg Pointer to the target dialog
- whichItem Index in the DITL of the item to draw
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- pascal void SheetfeederDrawProc(WindowPtr pDlg, short whichItem)
- {
- SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext();
- Handle hItem;
- Rect itemRect;
- short itemType;
-
- GetDItem(pDlg, whichItem, &itemType, &hItem, &itemRect);
-
- QDDrawPicture((*hGlobals)->sheetFeederPICT, &itemRect);
- }
- /* SheetfeederDrawProc */
-
-
- /****************************************************************************************
-
- GetConfigInfo
-
- function:
- This routine is a utility function that returns the LQ driver's configuration
- info. from the desktop printer file.
-
- parameters:
- configInfo Latest info fetched from the DTP file
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- OSErr GetConfigInfo(IWLQConfigInfoPtr configInfo)
- {
- OSErr anErr;
- Str32 deviceName;
- IWLQConfigInfoHdl hConfigData;
-
- // Get the name of the desktop printer file
- GXGetPrinterName(GXGetJobOutputPrinter(GXGetJob()), deviceName);
-
- // Get the config info
- anErr = GXFetchDTPData(deviceName, kIWLQConfigType, kIWLQConfigID, (Handle *) &hConfigData);
- require(anErr == noErr, FetchDTPData);
-
- // Return the config. info
- *configInfo = **hConfigData;
-
- // Kill the temporary handle
- DisposHandle((Handle) hConfigData);
-
-
- /******* Clean-up *******/
-
- FetchDTPData:
- return(anErr);
- }
- /* GetConfigInfo */
-
-
- /****************************************************************************************
-
- InitSheetfeederDialog
-
- function:
- This routine is called to initialize the sheet feeder dialog and to set the
- state of the pop-up menus based upon the latest configuration information.
-
- parameters:
- theDlog returns the pointer to the dialog window if init. was succesful; otherwise nil
- menuStuff info about the dialog's pop-up menus
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- OSErr InitSheetfeederDialog(DialogPtr *theDlog, PopupMenuInfoPtr menuStuff)
- {
- OSErr anErr = noErr;
- DialogPtr dLog;
- IWLQConfigInfo configInfo;
- SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext();
- short itemType;
- Rect itemRect;
- Handle hItem;
- gxPaperType paper;
-
- // Initialize variables
- *theDlog = nil;
- (*hGlobals)->sheetFeederPICT = nil;
-
- dLog = GetNewDialog(kSheetFeederDLOG, nil, (WindowPtr) (-1));
- if (dLog == nil)
- {
- anErr = MemError();
- if (anErr == noErr)
- anErr = resNotFound;
-
- require(anErr == noErr, GetNewDialog);
- }
-
- // Fetch the latest configuration info. from the DTP file
- anErr = GetConfigInfo(&configInfo);
- require(anErr == noErr, GetConfigInfo);
-
- // Determine which sheetfeeder picture to display in the dialog
- {
- short whichPICT;
- Handle thePICT;
-
- switch (configInfo.numTrays)
- {
- case 1: whichPICT = kOneTrayPICT; break;
- case 2: whichPICT = kTwoTrayPICT; break;
- case 3: whichPICT = kThreeTrayPICT; break;
- }
-
- anErr = Send_GXFetchTaggedDriverData('PICT', whichPICT, (Handle *) &thePICT);
- require(anErr == noErr, FetchTaggedDriverData);
-
- // Save this handle in our globals
-
- HNoPurge(thePICT);
- (*hGlobals)->sheetFeederPICT = (PicHandle) thePICT;
-
- // Setup the DrawProc for this picture item
-
- GetDItem(dLog, kPrinterPICTItem, &itemType, &hItem, &itemRect);
- SetDItem(dLog, kPrinterPICTItem, itemType, (Handle) SheetfeederDrawProc, &itemRect);
- }
-
- // Now fill in the pop-up menu paper type names and hide any pop-ups that don't apply
- // to the current configuration
- {
- PopupPrivateDataHandle privData;
- short i;
- MenuHandle *nextMenu;
-
- // Hide those pop-ups which don't apply to the current configuration
- if (configInfo.numTrays < 3)
- {
- HideDItem(dLog, kTray3Item);
- }
-
- if (configInfo.numTrays < 2)
- {
- HideDItem(dLog, kTray2Item);
- }
-
- // Init. the menuStuff structure in order to load the paper names into the pop-ups
-
- menuStuff->numTrays = configInfo.numTrays;
-
- for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu)
- {
- GetDItem(dLog, i, &itemType, &hItem, &itemRect);
- privData = (PopupPrivateDataHandle) (* (ControlHandle) hItem)->contrlData;
- *nextMenu = (*privData)->mHandle;
- }
-
- // Now load the paper type names into the remaining pop-up menus
- anErr = LoadPaperNames(dLog, menuStuff);
- require(anErr == noErr, LoadPaperNames);
- }
-
- // Retrieve the latest paper<->tray configuration and force the pop-up(s) to display the
- // correct paper name (i.e. the last selected paper name).
- {
- gxJob theJob = GXGetJob();
- MenuHandle *nextMenu;
- short i;
-
- // Create a temporary paper type
-
- paper = GXNewPaperType(theJob, NULL, NULL, NULL);
- anErr = GXGetJobError(theJob);
- require(anErr == noErr, NewPaperType);
-
- // For each visible pop-up menu, try to display the last choosen paper type
-
- for (i = kTray1Item, nextMenu = &(menuStuff->tray1Menu); i <= kTray3Item; ++i, ++nextMenu )
- {
- short whichTray = i - kTray1Item + 1;
-
- if ( whichTray <= menuStuff->numTrays ) // T => This menu is visible
- {
- Str255 menuString;
- short j;
- Str31 paperName;
-
- // Get the tray information for this tray
-
- anErr = GXGetTrayPaperType(whichTray, paper);
- if (anErr == resNotFound)
- anErr = noErr;
- else {
- require(anErr == noErr, GetTrayPaperType);
-
- // Fetch the name of the paper type
- GXGetPaperTypeName(paper, paperName);
-
- // For each paper name in the menu, try to find a match
-
- for (j = CountMItems(*nextMenu); j > 0; --j)
- {
- GetItem(*nextMenu, j, menuString);
-
- if ( IUCompString(paperName, menuString) == 0 ) // T => Found the string
- {
- // Make this paper name the current pop-up menu selection
-
- GetDItem(dLog, i, &itemType, &hItem, &itemRect);
- SetCtlValue((ControlHandle) hItem, j);
- break;
- }
- }
- }
- }
- else // T => No more visible pop-up menus
- break;
- }
-
- // Dump the temporary paper type
- GXDisposePaperType(paper);
- }
-
- *theDlog = dLog;
-
- return(anErr);
-
-
- /******* Clean-up *******/
-
- GetTrayPaperType:
- GXDisposePaperType(paper);
-
- NewPaperType:
- LoadPaperNames:
- DisposHandle((Handle) (*hGlobals)->sheetFeederPICT);
-
- FetchTaggedDriverData:
- GetConfigInfo:
- DisposDialog(dLog);
-
- GetNewDialog:
- return(anErr);
- }
- /* InitSheetfeederDialog */
-
-
- /***************************************************************************************
- * INTERFACE ROUTINES *
- ***************************************************************************************/
-
- /****************************************************************************************
-
- DoSheetfeederDialog
-
- function:
- This routine is called to display and process the LQ driver's sheetfeeder
- dialog. This dialog is displayed when the user selects the "Input Trays…" menu
- item from the Finder menu. This dialog allows the user to specify the type
- of paper that's contained within the printer's sheet feeder.
-
- parameters:
- None
-
- returns:
- OSErr error code
-
- ****************************************************************************************/
- OSErr DoSheetfeederDialog(void)
- {
- OSErr anErr = noErr;
- GrafPtr oldPort;
- DialogPtr theDlog;
- short itemHit = 0;
- PopupMenuInfo menuStuff;
- SpecGlobalsHdl hGlobals = GetMessageHandlerInstanceContext();
-
- GetPort(&oldPort);
-
- // Initialize the dialog before displaying it
- anErr = InitSheetfeederDialog(&theDlog, &menuStuff);
- require(anErr == noErr, InitSheetfeederDialog);
-
- // Make sure the dialog is now visible
- ShowWindow(theDlog);
- SelectWindow(theDlog);
-
- // Process events in the window
- while ( (itemHit != ok) && (itemHit != cancel) )
- {
- ModalDialog((ModalFilterProcPtr) SheetfeederDialogFilter, &itemHit);
- }
-
- // Do we need to save the new settings?
- if (itemHit == ok)
- anErr = SaveSheetfeederSettings(theDlog, &menuStuff);
-
- // Dump the dialog and picture handle
-
- if ( (*hGlobals)->sheetFeederPICT != nil )
- DisposHandle((Handle) (*hGlobals)->sheetFeederPICT);
-
- DisposDialog(theDlog);
-
- SetPort(oldPort);
-
- return(anErr);
-
-
- /******* Clean-up *******/
-
- InitSheetfeederDialog:
- SetPort(oldPort);
-
- return(anErr);
- }
- /* DoSheetfeederDialog */
-
-